
//
//  NetworkManager+Stutas.swift
//  Weibo(Swift)
//
//  Created by 阳 on 16/7/13.
//  Copyright © 2016年 阳. All rights reserved.
//

import UIKit

extension NetworkManager {
    
    ///  获取微博首页的数据
    ///
    ///  - parameter since_id: 下拉刷新传递, 返回比since_id大的数据,如果since_id传值,则max_id要传0
    ///  - parameter max_id:   上拉刷新传递, 返回小于或等max_id的数据, 如果max_id传值,则since_id要传0
    ///  - parameter callBack: 数据获取完成后回调.
    func requestStatus(since_id: Int64, max_id: Int64, callBack: ([String: AnyObject]?)->Void) {
        /// 如果access_token为nil, 则直接返回nil
        guard let access_token = UserAccount.shareUserAccount.access_token else {
            callBack(nil)
            return
        }
        let urlString = "https://api.weibo.com/2/statuses/home_timeline.json"
        let parameters: [String: AnyObject] = ["access_token": access_token, "since_id": String(since_id), "max_id": String(max_id)]
        let requestType = RequestType.GET
        
        ///  调用网络中间层获取微博数据
        self.request(urlString, type: requestType, parameters: parameters) { (response) -> Void in
            ///  完成回调
            callBack(response)
        }
    }
}